package ljl.alg.jianzhioffer.round3.medium;

public class _16_myPow {

    public double myPow(double x, int n) {
        long n2 = n;
        if (x != 0 && n2 < 0) {
            n2 = -n2;
            x = 1 / x;
        }

        double res = 1;
        while (n2 > 0) {
            if (n2 % 2 == 1)
                res *= x;
            x *= x;
            n2 >>= 1;
        }
        return res;
    }

}
